package com.example.ruralservicedigitalplatform.mapper;

import com.example.ruralservicedigitalplatform.domain.po.ShoppingCart;
import com.example.ruralservicedigitalplatform.domain.po.Summary;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {
    /**
     * 动态查询购物车
     * @param shoppingCart
     * @return
     */
    List<ShoppingCart> list(ShoppingCart shoppingCart);

    /**
     * 插入购物车数据
     * @param shoppingCart
     */
    @Insert("insert into shopping_cart(name, image, item_id, price,villager_id, amount, create_time, update_time, create_user, update_user) " +
            "values (#{name},#{image},#{itemId},#{price},#{villagerId},#{amount},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void insert(ShoppingCart shoppingCart);

    /**
     * 根据id修改商品数量
     * @param cart
     */
    @Update("update shopping_cart set quantity=#{quantity},amount=#{amount} where shopping_id=#{shoppingId}")
    void updateQuantityById(ShoppingCart cart);

    /**
     * 根据村民id删除购物车商品
     * @param villagerId
     */
    @Delete("delete from shopping_cart where villager_id=#{villagerId}")
    void deleteByVillagerId(Long villagerId);

    /**
     * 根据商品id删除购物车商品
     * @param id
     */
    @Delete("delete from shopping_cart where shopping_id=#{id}")
    void deleteById(Long id);

    /**
     * 插入总价
     * @param summary
     */
    @Insert("insert into summary(total, villager_id) values(#{total},#{villagerId}) ")
    void insertTotal(Summary summary);

    /**
     * 更新总价
     */
    void updateTotal(Long villagerId);

    /**
     * 根据villagerId删除总价
     * @param villagerId
     */
    @Delete("delete from summary where villager_id=#{villagerId}")
    void deleteTotalByVillagerId(Long villagerId);

    /**
     * 根据villagerId查询总价
     * @param villagerId
     */
    @Select("select * from summary where villager_id=#{villagerId}")
    Summary selectByVillagerId(Long villagerId);
}
